﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SolutionClass.aspx.cs"
	Inherits="Habito.Admini.SolutionClass" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"><title>Solution Class</title>
	<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery.jbind.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery.treeTable.js"> </script>
	<script src="../../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../Scripts/jquery.FixedHeadTable.js"> </script>
	<link href="../../Content/jquery.treeTable.css" rel="stylesheet" type="text/css" />
	<link href="../../Content/easyui.css" rel="stylesheet" type="text/css" />
	<script src="../Scripts/common.js" type="text/javascript"></script>
	<style type="text/css">
		ul li { line-height: 30px; }
		span { color: Blue; cursor: pointer; }
	</style>
</head>
<body>
	<div style="float: left; margin-left: 10px;">
		<div>
			<%--<input type="button" name="name" value="Add New Class" onclick="AddNewClass()" />
			<input type="button" name="name" value="Delete Selected" onclick="deleteClass()" />--%>
			<table id="logList" style="width: 430px;">
				<thead>
					<tr>
						<th style="width: 90px">
							<span onclick="AddNewClass()">Add</span>
						</th>
						<th style="">Product name</th>
					</tr>
					<tr id='logList_bt' style="display: none">
						<td>
							<span onclick="modify('{ID}','{ClassName}')">Modify </span>
							<span onclick="deleteClass('{ID}')">Delete</span></td>
						<td>{ClassName}</td>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<div id="win" iconcls="icon-save" title="My Window">Class Name:<input type="text"
		name="name" value="" id="classname" />
		<input type="hidden" name="name" value="" id="id" />
		<br />
		<br />
		<br />
		<input type="button" name="name" value="Save" onclick="saveClass();" />
		<input type="button" name="name" value="Cancel" onclick="close()" />
	</div>
	<script type="text/javascript">
		function saveClass() {
			var id = $("#id").val();
			if (id == "") {
				id = 0;
			}
			var name = $("#classname").val();
			if (name == "") {
				alert("The name can not be null");
				return;
			}
			$.ajax({
				url: window.location.href + "?SaveSolutionClass=1",
				cache: false,
				data: { id: id, className: name },
				success: function (data) {
					data = $.evalJSON(data);
					if (data != undefined && data.ID != undefined) {
						$("#win").window("close");
						alert("Save succeed!");
						$("#id").val("");
						$("#classname").val("");
						init();
					}
				},
				error: function (data) {
					alert();
				}
			});
		}

		function modify(id, name) {
			$("#classname").val(name);
			$("#id").val(id);
			$('#win').window({
				width: 300,
				height: 200,
				modal: true,
				collapsible: false
			});
		}

		$(document).ready(function () {
			init();
			$('#win').window({
				width: 300,
				height: 200,
				modal: true,
				collapsible: false
			});
			$("#win").window('close');
		});

		function init() {
			$.ajax({
				cache: false,
				url: window.location.href + "?GetAllSolutionClass=1",
				success: function (data) {
					data = $.evalJSON(data);
					$("#logList").treeTable({
						treeColumn: -1,
						key: "ID",
						bind: {
							templateID: "#logList_bt",
							data: data,
							ajaxPara: {},
							ajaxSuccess: function (re) { }
						}
					});
				}
			});
		}

		function AddNewClass() {
			$("#id").val(0);
			$('#win').window({
				width: 300,
				height: 200,
				collapsible: false,
				modal: true
			});
		}

		function close() {
			$("#win").close();
		}

		function deleteClass(id) {
			$.messager.confirm('Confirm', 'Are you sure you want to delete record?', function (r) {
				if (r) {
					$.ajax({
						cache: false,
						url: window.location.href + "?DeleteSolutionClass=1",
						data: { id: id },
						success: function (data) {
							if (data) {
								if (data) {
									$("#logList").ttGetItem(id).ttRemove();
									$("#id").val("");
									$("#classname").val("");
								}
							}
						},
						error: function (da) {
							alert();
						}
					});
				}
			});
		} 
	</script>
</body>
</html>
